package com.wenbiao.springcloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration  //等于spring applicationContext.xml配置文件
public class Beanconfig {

    /**
     * @Bean 等于
     *<bean id="restTemplate" class="xxxx.xxxx.xxxx.RestTemplate">
     *</bean>
     * @return
     */
    @LoadBalanced //使用Ribbon实现负载均衡
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 覆盖掉原来ribbon默认的轮询均衡策略
     * @return
     */

//    @Bean
//    public IRule iRule(){
////        return new RandomRule(); //随机的负载均衡策略
//        return new RetryRule(); //重试的负载均衡策略
//    }
}
